package uit.edu.vn.Activity;

import uit.edu.vn.Utility.MyActivity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class FileBackupActivity extends TabActivity{
	private Context context;
    private String username = "";
    private String password = "";
    private static final String STRING_NAME_USERSETTING = "USER REFERENCES";
    private SharedPreferences ShareRef = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
        username = getSetting("username");
        password = getSetting("password");		
		setContentView(R.layout.main_tabview);
        //kiem tra neu username va password rong thi ket thuc activity hien tai va goi activity login
	      if(username.equals("") && password.equals("")){
	          Intent intent = new Intent(FileBackupActivity.this, LoginActivity.class);
	          startActivity(intent);
	          this.finish();            	
	      }	
	      
	      System.out.println("FileBackupActivity");
	      System.out.println("username: "+ username);
	      System.out.println("password: "+ password);	      
		context=getBaseContext();
        //xu ly tab host

        Resources res = getResources(); // Resource object to get Drawables

        TabHost tabHost1= getTabHost();// The activity TabHost
        TabHost.TabSpec spec1;//Resusable TabSpec for each tab

        //Tao intent
        Intent intent;
        intent= new Intent().setClass(context, MusicActivity.class);

        // them vao tab host 
        spec1= tabHost1.newTabSpec("Music").setIndicator(getResources().getString(R.string.txt_Music),res.getDrawable(R.drawable.tab_music_selector)).setContent(intent);
        tabHost1.addTab(spec1);
        // add tab host
        intent= new Intent().setClass(this, ImageActivity.class);
        spec1= tabHost1.newTabSpec("image").setIndicator(getResources().getString(R.string.txt_Image),res.getDrawable(R.drawable.tab_image_selector)).setContent(intent);
        tabHost1.addTab(spec1);

        intent= new Intent().setClass(this, FileActivity.class);
        spec1= tabHost1.newTabSpec("file").setIndicator(getResources().getString(R.string.txt_File),res.getDrawable(R.drawable.tab_file_selector)).setContent(intent);
        tabHost1.addTab(spec1);
        tabHost1.setCurrentTab(0);
	}
	
	public String getSetting(String key) {
        ShareRef = getSharedPreferences(STRING_NAME_USERSETTING, Context.MODE_WORLD_WRITEABLE);
        return ShareRef.getString(key, "");
	} 	
	
}
